/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * <p>Project: javaseapp - List1
 * <p>Powered by webrx On 2021-08-09 14:47:51
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class List3 {
    public static void main(String[] args) {
        //固定的List，相当于一个特殊的数组
        List<String> list = List.of("java", "javascript", "php", "python", "c", "go", "ruby");
        list = new ArrayList<String>(list);
        System.out.println(list);
        //升序 a-z
        list.sort(String::compareTo);
        System.out.println(list);
        //降序 z-a
        list.sort(Comparator.reverseOrder());
        System.out.println(list);

        //按字母个数升序
        list.sort(Comparator.comparingInt(String::length));
        //按字母个数降序
        list.sort((a, b) -> b.length() - a.length());
        System.out.println(list);

        //list.clear(); 错误，原因是
        //System.out.println(list.size());

        //new ArrayList() 将固定的List
        List<String> listok = new ArrayList<>(list);
        //listok.clear();
        //System.out.println(listok.size());
        //System.out.println(listok);

        List<Integer> list2 = new ArrayList<>(Arrays.asList(10, 1, 0, 9, 8, 3, 25, 18, 60, 33));
        System.out.println(list2);
        //升序
        list2.sort((a, b) -> a - b);
        System.out.println(list2);
        //降序
        list2.sort((a, b) -> b - a);
        System.out.println(list2);

    }
}
